#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

vector<int>path;
vector<vector<int> >result;

void backtracking(vector<int>nums,vector<int>used,int startindex){
	if(path.size()==nums.size()){
		result.push_back(path);
	}
	for(int i=0;i<nums.size();i++){
		if(i>0&&used[i-1]==0&&nums[i-1]==nums[i]){
			continue;
		}
		if(used[i]==0){
		path.push_back(nums[i]);
		used[i]=1;
		backtracking(nums,used,i);
	    path.pop_back();
	    used[i]=0;
		} 

	}
}

int main()
{
	vector<int> nums={1,1,2};
	vector<int> used;
	for(int i=0;i<nums.size();i++){
		used.push_back(0);
	}
	backtracking(nums,used,0);
	for(vector<vector<int> >::iterator it=result.begin();it!=result.end();it++){
	for(vector<int>::iterator iit=(*it).begin();iit!=(*it).end();iit++){
			cout<<(*iit)<<' ';
		}
		cout<<endl;
	} 
	return 0;
 } 
